package com.fh.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws Exception {

		/* ============================================================================================= */
		String faobject = "";  				//主表名				========参数0-1 主附结构用
		String FHTYPE = "single";  					//模块类型			========参数0-2 类型，单表、树形结构、主表明细表
		String TITLE = "用户头像";  						//说明				========参数0
		String packageName = "system";  			//包名				========参数1
		String objectName = "UserPhoto";	   			//类名				========参数2
		String tabletop = "SYS_";	   				//表前缀				========参数3
		tabletop = null == tabletop?"":tabletop.toUpperCase();		//表前缀转大写
		String zindext = "5";	   	   			//属性总数
		int zindex = 0;
		if(null != zindext && !"".equals(zindext)){
			zindex = Integer.parseInt(zindext);
		}
		
		Map<String, String> map = new HashMap<String, String>();
		map.put("field0", "USERNAME,fh,String,fh,用户名,fh,否,fh,无,fh,30,fh,0");
		map.put("field1", "PHOTO0,fh,String,fh,原图,fh,否,fh,无,fh,100,fh,0");
		map.put("field2", "PHOTO1,fh,String,fh,头像1,fh,否,fh,无,fh,100,fh,0");
		map.put("field3", "PHOTO2,fh,String,fh,头像2,fh,否,fh,无,fh,100,fh,0");
		map.put("field4", "PHOTO3,fh,String,fh,头像3,fh,否,fh,无,fh,100,fh,0");
		
		List<String[]> fieldList = new ArrayList<String[]>();   	//属性集合			========参数4
		for(int i=0; i< zindex; i++){
			fieldList.add(map.get("field"+i).split(",fh,"));	//属性放到集合里面
	    }
//		for(int i=0; i< zindex; i++){
//			fieldList.add(pd.getString("field"+i).split(",fh,"));	//属性放到集合里面
//		}
		Map<String,Object> root = new HashMap<String,Object>();		//创建数据模型
		root.put("fieldList", fieldList);
		root.put("faobject", faobject.toUpperCase());				//主附结构用，主表名
		root.put("TITLE", TITLE);									//说明
		root.put("packageName", packageName);						//包名
		root.put("objectName", objectName);							//类名
		root.put("objectNameLower", objectName.toLowerCase());		//类名(全小写)
		root.put("objectNameUpper", objectName.toUpperCase());		//类名(全大写)
		root.put("tabletop", tabletop);								//表前缀	
		root.put("nowDate", new Date());							//当前日期
		
		DelAllFile.delFolder(PathUtil.getClasspath()+"admin/ftl"); //生成代码前,先清空之前生成的代码
		/* ============================================================================================= */
		String filePath = "admin/ftl/code/";						//存放路径
		String ftlPath = "createCode";								//ftl路径
		
		
		/*生成controller*/
		Freemarker.printFile("controllerTemplate.ftl", root, "controller/"+packageName+"/"+objectName.toLowerCase()+"/"+objectName+"Controller.java", filePath, ftlPath);
		/*生成service*/
		Freemarker.printFile("serviceTemplate.ftl", root, "service/"+packageName+"/"+objectName.toLowerCase()+"/impl/"+objectName+"Service.java", filePath, ftlPath);
		/*生成manager*/
		Freemarker.printFile("managerTemplate.ftl", root, "service/"+packageName+"/"+objectName.toLowerCase()+"/"+objectName+"Manager.java", filePath, ftlPath);
		/*生成mybatis xml*/
		Freemarker.printFile("mapperMysqlTemplate.ftl", root, "mybatis_mysql/"+packageName+"/"+objectName+"Mapper.xml", filePath, ftlPath);
		/*生成SQL脚本*/
		Freemarker.printFile("mysql_SQL_Template.ftl", root, "mysql数据库脚本/"+tabletop+objectName.toUpperCase()+".sql", filePath, ftlPath);
		
		
		
		
	}

}
